package com.zking.seckillpro.vaildator;

import com.zking.seckillpro.util.ValidatorUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 自定义手机号码格式验证
 */
public class MobileValidator implements ConstraintValidator<IsMobile,String> {

    private  boolean required=false;
    @Override
    public void initialize(IsMobile isMobile) {
    this.required=isMobile.required();
    }

    @Override
    public boolean isValid(String mobile, ConstraintValidatorContext constraintValidatorContext) {
        if (!this.required)
            return false;
        return ValidatorUtils.isMobile(mobile);
    }
}
